package proxy

import (
	"fmt"
	"golang.org/x/net/proxy"
	"lidongyooo/search-bot/pkg/config"
	"net/http"
)

func Client() *http.Client {
	if config.Viper.GetBool("PROXY.ENABLE") {
		dialSocks5, err := proxy.SOCKS5("tcp", fmt.Sprintf("%s:%s", config.Viper.GetString("PROXY.ADDRESS"), config.Viper.GetString("PROXY.PORT")), nil, proxy.Direct)
		if err != nil {
			fmt.Println(err)
		}

		transport := &http.Transport{Dial: dialSocks5.Dial}
		client := &http.Client{}
		client.Transport = transport

		return client
	}

	return &http.Client{}
}
